package logic

import (
	"context"
	"order_srv/model/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrderLogic {
	return &AddOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddOrderLogic) AddOrder(in *order.AddOrderRequest) (*order.AddOrderResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{
		Payment: int8(in.Payment),
		Status:  int8(in.Status),
		Amount:  float64(in.Amount),
		OrderSn: in.OrderSn,
		UserId:  int8(in.UserId),
	}
	err := o.Create()
	if err != nil {
		logx.Error("订单添加失败:", err)
		return nil, err
	}
	return &order.AddOrderResponse{}, nil
}
